package com.fa4j.common.web.model;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

@Data
@Schema(description = "响应")
@NoArgsConstructor
@AllArgsConstructor
public class ResponseVO<T> implements Serializable {

    @Schema(description = "是否成功")
    private boolean success = true;

    @Schema(description = "数据")
    private T data;

    @Schema(description = "错误编码")
    private Integer errCode;

    @Schema(description = "错误信息")
    private String errMsg;

    public static ResponseVO<?> success() {
        return success(null);
    }

    public static <T> ResponseVO<T> success(T data) {
        ResponseVO<T> responseVO = new ResponseVO<>();
        responseVO.setData(data);
        return responseVO;
    }

    public static <T> ResponseVO<T> error(Integer errCode, String errMsg) {
        ResponseVO<T> responseVO = new ResponseVO<>();
        responseVO.setSuccess(false);
        responseVO.setErrCode(errCode);
        responseVO.setErrMsg(errMsg);
        return responseVO;
    }
}
